package com.weeego.web.action;

import com.sql.weeego.bean.base.CenterNewsType;
import com.weeego.web.base.BaseAction;
import com.weeego.web.service.CentterNewsTypeService;
import java.util.HashMap;
import java.util.Map;

public class CentterNewsTypeAction extends BaseAction {

	protected CentterNewsTypeService centterNewsTypeService;

	public CentterNewsTypeService getCentterNewsTypeService() {
		return centterNewsTypeService;
	}

	public void setCentterNewsTypeService(
			CentterNewsTypeService centterNewsTypeService) {
		this.centterNewsTypeService = centterNewsTypeService;
	}

	public CentterNewsTypeAction() {
		super();
		this.objectForm = new CenterNewsType();
	}

	Map msg = new HashMap();
	private String name;
	private String typekey;
	private String ids;
	// 用来标记查找类别
	private String type;

	public void setType(String type) {
		this.type = type;
	}

	@Override
	public String save() {
		try {
			this.centterNewsTypeService.saveOrUpdate(objectForm);
			// savelog("save the objectForm . the object" + " value is :" +
			// objectForm);
			logger.info("save the objectForm . the object" + " value is :"
					+ objectForm);
			return "success";
		} catch (Exception ex) {
			return ERROR;
		}
	}

	@Override
	public String action() {
		if (this.getAct() == 1) {
			CenterNewsType _CenterNewsType = new CenterNewsType(name, typekey);
			logger.info(_CenterNewsType);
			return "add" + centterNewsTypeService.save(_CenterNewsType);
		} else if (this.getAct() == 2) {
			this.commondResult = getText("center.news.del.ok");
			return "delsuccess";
		} else if (this.getAct() == 3) {

			return "editsuccess";
		} else if (this.getAct() == 7) {
			this.hql = "from   CenterNewsType t  where t.typeKey  like 'weeego__' and(not t.typeState like 'del' )order by t.typeState ";
			this.autolist = findByHql(hql);
			return "list";
		} else {
			return SUCCESS;
		}
	}

	@SuppressWarnings("unchecked")
	public String getTypeForWeeego() {
		autolist = this
				.findByHql(" from   CenterNewsType t  where t.typeKey  like 'weeego"
						+ type + "__' and t.typeState like 'weeego'");
		if (this.autolist == null) {
			this.commondResult = getText("center.news.list.null");
			return ERROR;
		} else {
			return "list" + SUCCESS;
		}
	}

	@SuppressWarnings("unchecked")
	public Map getMsg() {
		return msg;
	}

	public void setMsg(Map msg) {
		this.msg = msg;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

	public String getTypekey() {
		return typekey;
	}

	public void setTypekey(String typekey) {
		this.typekey = typekey;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
